<?php

$Username = $_REQUEST['Username'];
$UserType = $_REQUEST['UserType'];
$StaffName = $_REQUEST['StaffName'];
$centreId = intval($_REQUEST['CentreName']);
$ContactNumber = intval($_REQUEST['ContactNumber']);
$Email = $_REQUEST['Email'];

include 'conn.php';


if ($centreId == 0) {//User has been updated but centre has not been changed
    $sql = "UPDATE user SET UserType='$UserType',StaffName='$StaffName', ContactNumber='$ContactNumber',Email='$Email' WHERE Username='$Username'";
    $result = @mysql_query($sql);

    if ($result) {
        echo json_encode(array('success' => true));
    } else {
        echo json_encode(array('msg' => 'Some errors occured.'));
    }
} else if ($centreId == -1) {//Centre has been removed
    $sql = "UPDATE user SET UserType='$UserType',StaffName='$StaffName',CentreId = NULL, ContactNumber='$ContactNumber',Email='$Email' WHERE Username='$Username'";
    $result = @mysql_query($sql);

    if ($result) {
        echo json_encode(array('success' => true));
    } else {
        echo json_encode(array('msg' => 'Some errors occured.'));
    }
} else {
    $sql = "UPDATE user SET UserType='$UserType',StaffName='$StaffName',CentreId = '$centreId', ContactNumber='$ContactNumber',Email='$Email' WHERE Username='$Username'";
    $result = @mysql_query($sql);

    if ($result) {
        echo json_encode(array('success' => true));
    } else {
        echo json_encode(array('msg' => 'Some errors occured.'));
    }
}
?>